<?php

/**
 * Created by PhpStorm.
 * User: evan
 * Date: 2017/3/5
 * Time: 下午6:43
 */
class News extends MY_Www_Controller
{
    public function index()
    {
        $limit  = 4;
        $page   = intval($this->input->get_post('page'));
        $page   = $page ? $page : 1;
        $offset = ($page - 1) * $limit;
        $cid = (int)$this->input->get_post('cid');


        !$cid && $cid = 10;


        $where = array('is_view' => ARTICLE_IS_VIEW_SHOW);
        $cid && $where['cid'] = $cid;


        $this->load->model('article/Model_article', 'a');


        $news = $this->a->lists($offset, $limit, $where, true, 'create_time DESC');
        $total_rows = $this->a->count($where);


        $this->load->model('article/Model_article_cate', 'ac');
        $news_cate = $this->ac->lists(OFFSET, LIMIT, array('pid' => 9), true, 'sort asc');


        //分页
        $this->load->library('pagination');

        $config['total_rows'] = $total_rows;
        $config['per_page'] = $limit;
        $config['base_url'] = '/News/index';

        $this->pagination->initialize($config);
        $page_html = $this->pagination->create_links();


        $data = array
        (
            'cid'  => $cid,
            'news' => $news,
            'news_cate' => $news_cate,
            'page_html' => $page_html,
        );


        $this->load->view('www/news/index', $data);
    }


    public function detail()
    {
        $aid = (int)$this->input->get_post('aid');


        if (!$aid)
        {
            show_error('资讯ID为空!');
        }


        $this->load->model('article/Model_article', 'a');
        $item = $this->a->getById($aid);


        $company_news   = $this->a->lists(OFFSET, 3, array('cid' => 10));
        $industry_news  = $this->a->lists(OFFSET, 3, array('cid' => 11));
        $company_active = $this->a->lists(OFFSET, 2, array('cid' => 12));
        $company_notice = $this->a->lists(OFFSET, 2, array('cid' => 13));

        $data = array
        (
            'item' => $item,
            'company_news'   => $company_news,
            'industry_news'  => $industry_news,
            'company_active' => $company_active,
            'company_notice' => $company_notice,
        );
        $this->load->view('www/news/detail', $data);
    }
}